package com.example.asapp.user.detail;

import com.example.asapp.base.BaseApi;
import com.example.asapp.base.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
@RestController
@Slf4j
@RequestMapping("/api/user/detail")
public class DetailApi extends BaseApi {

    @Autowired
    DetailService detailService;

    @GetMapping("listQuery")
    public List<Detail> findAll(){
        return detailService.findAll();
    }

    @PostMapping("save")
    public Detail saveOne(@RequestBody Detail detail){
        log.info("detail is {}",detail);
        detail.setPassword("123456");
        return detailService.saveOne(detail);
    }

    @DeleteMapping("delete/{id}")
    public void deleteOne(@PathVariable String id){
       detailService.deleteByPrimary(id);
    }


    @PostMapping("login")
    public UserInfo login(@RequestBody Detail detail){
        return detailService.login(detail);
    }

    @GetMapping("loginByToken")
    public UserInfo loginByToken(){
        return getUserInfo();
    }

}
